package com.aaa.qy127.controller;

import com.aaa.qy127.service.GWCService;
import com.aaa.qy127.util.CodeAndMsg;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RequestMapping("/gwc")
@RestController
public class GWCController {

    /**
     * 注入 GWCService
     */
    @Resource(name = "gwcServiceImpl")
    private GWCService gwcService;

    /**
     * 将 选择 的 商品 加入 到 购物车中
     * @param bookid
     * @param count
     * @param outprice
     */
    @RequestMapping("/insertGwc")
    public CodeAndMsg insertGwc(String bookid, String count, String outprice, HttpServletRequest request){
        CodeAndMsg codeAndMsg = gwcService.insertGwc(bookid, count, outprice, request);
        return codeAndMsg;
    }

    /**
     * 查询该用户 所有的 购物车 中 的信息
     * @param request
     * @return
     */
    @RequestMapping("/selectAllGWC")
    public List<Map<String,Object>> selectAllGWC(HttpServletRequest request){
        List<Map<String, Object>> maps = gwcService.selectAllGwc(request);
        return maps;
    }

    /**
     * 通过 gwcid 修改 gwc 中的 值
     * @param gwcid
     * @return
     */
    @RequestMapping("/updatecountByGwcid")
    public List<Map<String,Object>> updatecountByGwcid(String gwcid,String count,HttpServletRequest request){
        //System.out.println(gwcid);
        List<Map<String, Object>> maps = gwcService.updatecountByGwcid(gwcid, count, request);
        return maps;
    }

    /**
     * 通过 gwcid 删除 一条数据之后 再查询一次 所有信息 并返回到 页面
     * @return
     */
    @RequestMapping("/deleteGwcByGwcid")
    public List<Map<String,Object>> deleteGwcByGwcid(String gwcid, HttpServletRequest request){
        List<Map<String, Object>> maps = gwcService.deleteGwcByGwcid(gwcid, request);
        return maps;
    }
}
